Integration Guide FANUC

Note: Read the Robot communication overview before you read this integration guide.

Note 2: This guide describes the FANUC Robot module BPS 1.12.1 for Bin Picking Studio (BPS) 1.12. We strongly recommend that you use the latest version of the Robot module. You can download the Robot module from the official Photoneo website. Supported versions of all Robot modules are listed in the Robot module support matrix.

Contents

1 Prerequisites

Before the setup, make sure that your robot controller meets these requirements:

  • Controller software: FANUC controller with system software V8.30 - V9.40 (the Robot module contains KAREL binaries for V8.x and V9.x).

    To check the system version, go to Menu -> Next -> Status -> Version ID.

    Older versions (V6.40 - V8.20) need a custom build of the KAREL binaries and older TP syntax. For these versions, contact support@photoneo.com.

  • Option R648 User Socket Msg - TCP/IP socket communication with the vision controller.

  • Option R632 KAREL - the communication with the vision controller is written in KAREL and runs as compiled .PC programs.

To check that the options are installed, go to Menu -> Next -> Status -> Version ID -> Next -> F3[ORDER FI]:

Ordered options R632 KAREL and R648 User Socket Msg

2 Robot controller setup

2.1 Controller configuration

2.1.1 Setting the IP addresses of the Ethernet ports

Configure the IP address of the controller port that is connected to the vision controller (directly or through a switch).

On the teach pendant, press Menu -> Setup -> Host Comm -> TCP/IP -> F3[Detail]:

SETUP Protocols screen with TCP/IP selected

Press F3[PORT] to switch between Port#1 and Port#2. Set the IP address and subnet mask of the port to match your network:

Port#1 IP address on the TCP/IP screen

If you use ROBOGUIDE or transfer files over the network, you can use the second port for this:

Port#2 IP address on the TCP/IP screen

Example of a matching network configuration:

  • Vision controller: 192.168.1.1 / 255.255.255.0

  • Robot controller: 192.168.1.2 / 255.255.255.0

To check the connection, ping the vision controller from the PING screen of Host Comm (enter the IP address of the vision controller into Remote name/IP and press PING). You can also use Test connection on the Network page of the Studio to ping the robot controller.

2.1.2 Configuring the TCP/IP server

The Robot State Server (KAREL program PHOSTATE) runs on the robot controller as a TCP/IP server. The vision controller connects to it as a client. The server uses Host Comm server tag S3. Tags S1 and S2 stay free for other applications.

Press Menu -> Setup -> Host Comm -> F4[SHOW] and select Servers. Select the S3 tag and press F3[DETAIL]:

SETUP Servers screen with tag S3 selected

Set the tag as follows:

  • Comment: PHOSTATE

  • Protocol: SM

  • Startup State: START

Do not set the port. When PHOSTATE starts, it writes port 11004 to $HOSTS_CFG[3].$SERVER_PORT itself.

Host Comm server tag S3

Cycle the power of the robot controller. After the restart, the Current State of S3 must be STARTED.

2.1.3 Configuring the TCP/IP client

The Action Request Client (KAREL program PHOCLIENT) connects to the Action Request Server on the vision controller. The client uses Host Comm client tag C3. Tags C1 and C2 stay free for other applications.

Press Menu -> Setup -> Host Comm -> F4[SHOW] and select Clients. Select the C3 tag and press F3[DETAIL]:

SETUP Clients screen with tag C3 selected

Set the tag as follows:

  • Comment: PHOCLIENT

  • Protocol: SM

  • Startup State: START

  • Server IP/Hostname: IP address of the vision controller (as shown on the Network page of the Studio)

Do not set Remote Port or Port. When PHOCLIENT starts, it writes port 11003 to $HOSTC_CFG[3].$SERVER_PORT itself.

Host Comm client tag C3

Cycle the power of the robot controller. After the restart, the Current State of C3 must be STARTED.

2.1.4 Changing the Cartesian origin of the robot

BPS uses a robot base frame at the bottom of the robot base (on the J1 axis). The FANUC World frame is higher, at the intersection of J1 and J2. The Robot State Server must report the robot pose in the Photoneo frame. Otherwise, calibration and hand-eye scanning do not work.

To do this, use one user frame and one tool frame:

  • UFRAME (default User Frame 1) - all values are zero except Z. Set Z to the negative offset of your robot model from the Base frame offsets page.

  • UTOOL (default Tool Frame 1) - all values are zero (bare flange). You can teach your real gripper TCP in another tool frame.

Press Menu -> Setup -> Frames, press F3[OTHER] and select User Frame:

SETUP menu with Frames selected

Edit the Z value of the user frame:

User Frame 1 with negative Z offset

Warning: If you change a user frame, this can affect Cartesian positions that were taught in this frame!

Two registers select the frame numbers. They are set in the TP program PHO_RUN_STATE (default 1 and 1). If you use other frames, edit lines 9 and 11 of PHO_RUN_STATE:

  • R[33] - UFRAME number: 1 - 9, or 0 for the World frame

  • R[34] - UTOOL number: 1 - 10, or 0 for the bare faceplate

The registers always apply. The Robot State Server reads them in every cycle. They do not change the frames that are active for your TP programs. An invalid number is rejected: PHOCLIENT sets R[18] to Bad data (4), and PHOSTATE keeps the active frame and writes a message to the USER screen.

Note: Bin picking trajectories are sent as joint positions, so the frames do not affect the motion of the bin picking routine.

2.2 Robot module installation

2.2.1 Loading the Robot module files

The Robot module archive contains:

Folder / file

Content

Karel/v8/

PHOCLIENT.PC, PHOSTATE.PC - compiled KAREL programs for controller software V8.x

Karel/v9/

PHOCLIENT.PC, PHOSTATE.PC - compiled KAREL programs for controller software V9.x

Karel/

phoclient.kl, phostate.kl - KAREL source code (for reference only - do not load it to the robot)

TP/

47 TP programs (.TP, binary) - load these to the robot

LS/

The same 47 TP programs as ASCII text (.LS) - for reading and comparing

README.md, CHANGELOG.md

Short instructions and version history

The TP programs are:

Group

TP programs

Request programs (do not edit)

PHO_INIT, PHO_REQ_SCAN, PHO_WAIT_SCAN, PHO_TRAJ_REQ, PHO_TRAJ_RECV, PHO_PICK_FAIL, PHO_REQ_OBJ_POSE, PHO_CHANGE_ENV, PHO_CHANGE_BBOX, PHO_REQ_GET_STATUS, PHO_REQ_CAPTURE, PHO_REQ_REUSE_SCAN, PHO_BIN_LOC, PHO_CALIB_ADD, PHO_CALIB_START, PHO_CALIB_STOP, PHO_CALIB_SAVE, PHO_CHANGE_SOL, PHO_REQ_START_SOL, PHO_REQ_STOP_SOL, PHO_REQ_RUN_SOL, PHO_REQ_COM_CHECK

Bin picking procedures

PHO_PICK_PART (do not edit), PHO_EXE_TRAJ (edit speeds only), PHO_GRIPPER_ACT (do not edit), PHO_GRIP_ATT, PHO_GRIP_DEATT, PHO_GRIP_USER1, PHO_GRIP_USER2, PHO_GRIP_USER3 (user code)

Auxiliary programs

PHO_CLEAR_VARS, PHO_RUN_STATE

Example programs

PHO_MAIN_BASIC, PHO_MAIN_BASIC_HAND_EYE, PHO_MAIN_BASIC_MULTI_VS, PHO_MAIN_CHANGE_SOL, PHO_MAIN_CHANGE_ENV, PHO_MAIN_CHANGE_BBOX, PHO_MAIN_GET_OBJECT_POSE, PHO_MAIN_GET_STATUS, PHO_MAIN_MULTIVIEW_STATIC, PHO_MAIN_MULTIVIEW_DYNAMIC, PHO_MAIN_REUSE_SCAN, PHO_MAIN_COM_CHECK, PHO_CALIBRATION, PHO_CALIBRATION_STATIC, PHO_CALIBRATION_HAND_EYE

Copy the Karel and TP folders to a USB stick and plug it into the teach pendant (UT1:) or into the USB port of the controller cabinet (UD1:).

Press Menu -> File -> File -> F5[UTIL] and select Set Device:

FILE screen with UTIL menu and Set Device

Select the device where the USB stick is plugged in:

Device menu with USB on TP (UT1:)

Open the Karel folder and then the v8 or v9 folder that matches your controller software. Select PHOCLIENT.PC and press F3[LOAD], then do the same for PHOSTATE.PC.

Open the TP folder, select the item for all TP programs (*.TP or *.*) and press F3[LOAD] to load all TP programs at once:

FILE screen with all TP programs selected

Press the Select button to check that all TP programs and both KAREL programs are loaded:

Select screen listing the loaded programs

Note: Load only the .PC files. The .KL files are source code and cannot be run.

When PHOCLIENT runs for the first time, it writes comments to all registers, flags and position registers used by the Robot module.

3 Robot module

You can integrate the Robot module into your existing TP programs. Two KAREL programs run as background tasks:

  • PHOCLIENT - the Action Request Client. It sends requests to the vision controller and receives the responses.

  • PHOSTATE - the Robot State Server.

The TP programs of the Robot module communicate with PHOCLIENT through registers and flags. A request program writes the request ID to R[15], sets F[2] and waits until PHOCLIENT resets it. When the response arrives, PHOCLIENT sets F[4].

3.1 Robotic API

Note: Read the Photoneo robotic API before you read this section.

3.1.1 Connection procedures

Command

Description / Usage

Connect to Action Request Server

RUN PHOCLIENT
Description
Starts the KAREL task PHOCLIENT. The task writes port 11003 to $HOSTC_CFG[3].$SERVER_PORT, pings the vision controller that is set in Host Comm C3 and connects to it. Then it sends the brand ID and sets F[1].

Usage
Run it once at the beginning of the main program, after CALL PHO_CLEAR_VARS. Run it again after the connection is closed (F[1] is OFF).
Wait for connection to Action Request Server

WAIT (F[1]=ON)
Description
Waits until the connection is established (flag F[1: PHO CONNECTED] is ON).

Usage
Use it directly after RUN PHOCLIENT.

To stop PHOCLIENT, use Function -> Abort All. It also stops by itself after a communication error or a fatal error (see Error handling).

3.1.2 Communication procedures

Note: For a detailed description of the requests, see Action requests.

Warning: Do not edit these TP programs!

Every request writes its error code to R[18: PHO ERROR DATA] (0 = no error). Synchronous programs wait for the response. Asynchronous programs only send the request. The program in the Outputs column receives the response.

TP program

ID

Inputs

Outputs

PHO_INIT

4

R[30] - vision system ID
R[4] - number of the PR with the start pose
R[5] - number of the PR with the end pose
PR[R[4]], PR[R[5]] - start / end pose (Joint)

R[18]

PHO_REQ_SCAN

1

R[30] - vision system ID

Asynchronous - call PHO_WAIT_SCAN

PHO_WAIT_SCAN

-

-

R[18]

PHO_TRAJ_REQ

2

R[30] - vision system ID

Asynchronous - call PHO_TRAJ_RECV

PHO_TRAJ_RECV

-

-

R[18]
R[20] - R[26] - Info data
F[7] - pick allowed
PHOCLIENT keeps the trajectory, and PHO_PICK_PART executes it.
PHO_PICK_FAIL

7

R[30] - vision system ID

R[18]

PHO_REQ_OBJ_POSE

8

R[30] - vision system ID

R[18]
PR[20] - object pose (Cartesian, mm / deg)
R[23] - R[26] - Info data
PHO_CHANGE_ENV

15

R[19] - scene state ID

R[18]

PHO_REQ_GET_STATUS

21

R[30] - vision system ID

R[18]
R[7] - localized objects
R[8] - objects with planned trajectory
R[9] - 1 = still running, 0 = finished
PHO_REQ_CAPTURE

28

R[30] - vision system ID
R[33], R[34] - frames of the sent tool pose
F[8] - dynamic meshing ON/OFF
R[35] - gap between scans in ms (dynamic meshing)

Asynchronous - call PHO_WAIT_SCAN

PHO_REQ_REUSE_SCAN

29

R[30] - vision system ID

R[18]

PHO_CHANGE_BBOX

32

R[30] - vision system ID
R[37] - bounding box ID

R[18]

PHO_CALIB_ADD

5

- (the robot pose comes from the Robot State Server)

R[18] - the program stops with ABORT if R[18] is not 0

PHO_CALIB_START

25

R[31] - solution ID
R[30] - vision system ID

R[18]

27

-

R[18]
R[32] - calibration accuracy (mm)
PR[19] - calibration result pose

26

-

R[18]

PHO_CHANGE_SOL

9

R[31] - solution ID

R[18]

PHO_REQ_START_SOL

10

R[31] - solution ID

R[18]

PHO_REQ_STOP_SOL

11

-

R[18]

PHO_REQ_RUN_SOL

12

-

R[18]
R[31] - running solution ID
PHO_REQ_COM_CHECK

100

-

R[18]

PHO_BIN_LOC

3

R[30] - vision system ID

Reserved for a future Bin localization request. Not supported by BPS 1.12.

Note: The request Get available solutions (deprecated) is not available in the FANUC Robot module.

3.1.3 Bin picking procedures

Bin picking procedure

Description / Usage

Execute bin picking routine
PHO_PICK_PART
Executes the received bin picking routine - all trajectory segments and gripper commands in the order defined by the grasping method. Do not edit.

Call it after PHO_TRAJ_RECV returns R[18]=0. The robot must be in the start pose. At the end, the robot is in the end pose with the object in the gripper. If no trajectory was received (F[7] is OFF), the program stops with ABORT.

Warning: If you use several vision systems with different start poses, make sure that the robot is in the start pose of the correct vision system.
Execute trajectory segment
PHO_EXE_TRAJ

Moves through the joint waypoints of one trajectory segment (PR[21] - PR[120]). Called by PHO_PICK_PART. You can edit only the speed settings. See Bin picking routine execution settings.

Gripper command switch
PHO_GRIPPER_ACT

Calls the gripper program selected by R[17] (1 = attach, 2 = detach, 3 - 5 = user 1 - 3). Called by PHO_PICK_PART. Do not edit.

Gripper attach
PHO_GRIP_ATT

Empty by default. Add the commands that close the gripper. Called when a waypoint of the grasping method is set to run Attach.

Gripper detach
PHO_GRIP_DEATT

Empty by default. Add the commands that open the gripper. Called when the waypoint is set to run Detach. Good practice: run Detach at the start waypoint so that the gripper is open before picking.

Gripper user-defined 1 - 3
PHO_GRIP_USER1, PHO_GRIP_USER2, PHO_GRIP_USER3

Empty by default. Called when the waypoint is set to run User 1, User 2 or User 3.

3.1.4 Auxiliary procedures

Auxiliary procedure

Description / Usage

Clear variables
PHO_CLEAR_VARS

Resets flags F[1], F[2], F[4] - F[8] and registers R[10] - R[29]. Call it at the beginning of the main program, before RUN PHOCLIENT.

Start Robot State Server
PHO_RUN_STATE

Stops a running PHOSTATE (F[9] ON for 1 s), sets the reporting frames R[33] and R[34] and starts PHOSTATE. Call it at the beginning of the main program, or run it alone (for example, for manual calibration). See Robot State Server.

3.1.5 List of used registers

The Robot module reserves F[1] - F[10], R[1] - R[50] and PR[1] - PR[120]. Do not use them for other purposes. R[38] - R[50] are reserved for future use. PHOCLIENT writes the comments automatically.

Flags

Flag

Set by

Description

F[1: PHO CONNECTED]

module

ON while PHOCLIENT is connected to the vision controller.

F[2: PHO NEW REQ]

module

Set by a request program, reset by PHOCLIENT when it accepts the request.

F[3: PHO STATE SERVER]

module

ON while PHOSTATE is running.

F[4: PHO RES RECEIVED]

module

Set by PHOCLIENT when the response to the last request has been received.

F[5: PHO OPER READY]

module

The next operation of the bin picking routine is ready (used by PHO_PICK_PART).

F[6: PHO OPER FINISH]

module

The operation of the bin picking routine is finished (used by PHO_PICK_PART).

F[7: PHO PICK ALLOWED]

module

A valid trajectory has been received and PHO_PICK_PART can run.

F[8: PHO MESH DYNAMIC]

user

Dynamic meshing. Set it ON before PHO_REQ_CAPTURE to capture scans continuously. Set it OFF to stop capturing. OFF = one scan per PHO_REQ_CAPTURE.

F[9: PHO STATE KILL]

user

Set it ON to stop PHOSTATE. PHO_RUN_STATE resets it.

F[10: PHO USE MNU VARS]

-

Deprecated since 1.12.1. Has no effect. R[33] and R[34] always apply.

Registers

Register

Set by

Description

R[1: PHO TRAJ CURR]

module

Number of the trajectory segment being executed (1, 2, …). Used in PHO_EXE_TRAJ to select the speed.

R[2: PHO BP SPEED]

PHO_EXE_TRAJ

Speed (%) of the trajectory segment being executed.

R[3: PHO WPT CURR]

module

Waypoint counter in PHO_EXE_TRAJ.

R[4: PHO START POSE ID]

user

Number of the PR with the start pose for PHO_INIT.

R[5: PHO END POSE ID]

user

Number of the PR with the end pose for PHO_INIT.

R[6: PHO SYSTEM STATUS]

module

Current state of PHOCLIENT (for example, for a PLC): 0 waiting for a request, 1 - 200 request with this ID in progress (200 = picking), 500 booting, 501 disconnected, 503 error handling.

R[7: PHO NUM LOCALIZED]

module

Number of localized objects (PHO_REQ_GET_STATUS).

R[8: PHO NUM PLANNED]

module

Number of objects with a planned trajectory (PHO_REQ_GET_STATUS).

R[9: PHO CURR VS STATE]

module

1 = vision system still running, 0 = finished (PHO_REQ_GET_STATUS).

R[10] - R[14], R[16], R[17]

module

Internal registers of the bin picking routine: total / current operation, trajectory size, last-but-one and last waypoint PR, operation type, gripper command.

R[15: PHO REQ TYPE]

module

ID of the request sent by the last request program.

R[18: PHO ERROR DATA]

module

Error code of the last request (0 = no error). See Error codes.

R[19: PHO ENV ID]

user

Scene state ID for PHO_CHANGE_ENV.

R[20] - R[29]

module

Info data 1 - 10 (R[29] is reserved).

R[30: PHO VISION ID]

user

Vision system ID used by the next request.

R[31: PHO SOLUTION ID]

user / module

Solution ID for PHO_CHANGE_SOL, PHO_REQ_START_SOL and PHO_CALIB_START. Set to the running solution by PHO_REQ_RUN_SOL.

R[32: PHO CALIB ACCURACY]

module

Calibration accuracy in mm (real value), set by PHO_CALIB_SAVE.

R[33: PHO STATE MNUFRAME]

user

UFRAME used to report the robot pose (1 - 9, 0 = World). Set in PHO_RUN_STATE.

R[34: PHO STATE MNUTOOL]

user

UTOOL used to report the robot pose (1 - 10, 0 = bare faceplate). Set in PHO_RUN_STATE.

R[35: PHO CAPTURE GAP]

user

Delay between scans in dynamic meshing, in ms (0 - 10000; other values use 500 ms).

R[36: PHO TIMEOUT COUNTER]

module

Time in ms that the last response took to arrive (diagnostics).

R[37: PHO BBOX ID]

user

Bounding box ID for PHO_CHANGE_BBOX.

Position registers

The default number of position registers is often 100. Increase it to at least 120. You do this in a Controlled Start (contact your FANUC support if needed). Be careful - this maintenance operation can delete taught data!

Position register

Set by

Description

PR[1: PHO HOME]

user

Home pose (used in some examples, optional).

PR[2] - PR[17]

user

Start and end poses of vision systems 1 - 8 (PR[2] / PR[3] = start / end of VS1, PR[4] / PR[5] = VS2, …). Must be in Joint representation. Selected by R[4] and R[5]. Several vision systems can share the same poses.

PR[18]

-

Reserved.

PR[19: PHO CAL POSE]

module

Calibration result pose from PHO_CALIB_SAVE (Cartesian).

PR[20: PHO OBJ POSE]

module

Object pose from PHO_REQ_OBJ_POSE (Cartesian, mm / deg). Raw localization pose - no gripping point or invariance is applied. It is in the robot base frame of the Studio, so use it with the same UFRAME as R[33].

PR[21] - PR[120]

module

Joint waypoints of the trajectory segment being executed (up to 100 per segment). Filled by PHOCLIENT during PHO_PICK_PART.

3.1.6 Info data

Info data are stored in numeric registers. R[20] - R[28] and R[32] hold real values. A register keeps its value until a new response contains the same key.

Key

Info data

Register

Unit in robot

1

Tool point invariance

R[20: PHO TOOL PT INV]

index

2

Gripping point ID

R[21: PHO GRIP PT ID]

index

3

Gripping point invariance

R[22: PHO GRIP PT INV]

index

4

Dimension X

R[23: PHO OBJ DIM X]

mm

5

Dimension Y

R[24: PHO OBJ DIM Y]

mm

6

Rotation Z

R[25: PHO OBJ ROT Z]

deg (converted from mrad)

7

Neural network label

R[26: PHO NN LABEL]

integer

8

Max Z height

R[27: PHO LAYER MAX Z HEIGHT]

mm

9

Tilt

R[28: PHO LAYER TILT]

deg (converted from mrad)

10

Calibration accuracy

R[32: PHO CALIB ACCURACY]

mm (converted from µm)

11

Running solution ID

R[31: PHO SOLUTION ID]

integer

12

Number of localized objects

R[7: PHO NUM LOCALIZED]

integer

13

Number of ready objects

R[8: PHO NUM PLANNED]

integer

14

Processing state

R[9: PHO CURR VS STATE]

0 / 1

3.1.7 Error codes

The error code of the last request is stored in R[18]. The Error codes page describes the meaning of each code and how to fix the error. The KAREL programs use the following constant names:

Constant in PHOCLIENT

Value

Meaning

OK

0

No error

SERVICE_ERR

1

Service error

COMM_FAILURE

3

Communication error - socket error, wrong response, checksum error or no response within 30 s. Set by the Robot module.

BAD_DATA

4

Bad data - invalid frame number in R[33] / R[34]. Set by the Robot module.

LONG_TRAJ

6

Trajectory segment longer than 100 waypoints. Set by the Robot module.

BRAND_ERR

7

Brand does not match

SIMUL_M_ERR

8

Bin picking in simulation mode

UNKNOWN_ERR

200

Unknown error

PLAN_FAILED

201

Path planning failed

NO_PART

202

No object found

NOT_INIT

203

Vision system not initialized

EMPTY_SC_ERR

218

Empty scene

UKNOWN_STATE

219

Unable to read vision system pose

SCENE_NOT_AV

220

Scene state not found

SCENE_ACTIVE

221

Scene state already active

MULTI_NOT_EN

222

Invalid bounding box

WRNG_BP_CONF

255

Wrong bin picking configuration

INVALID_SOL … SOL_FORBID

450 - 459

Errors from Solution action requests

INVALID_VS … CALIB_FORBID

460 - 469

Automatic calibration errors

Other codes from the vision controller (for example calibration point errors or No valid license (471)) are written to R[18] unchanged.

3.2 Example programs

The example programs show the correct use of the robotic API. They contain only basic error handling. Add the error handling that your application needs. Before you run an example, touch up its positions (P[...]) and the start / end PRs.

Example program

Purpose

PHO_MAIN_BASIC

Basic bin picking with a cell-mounted scanner: initialize one vision system, scan, request and receive the trajectory, pick, repeat.

PHO_MAIN_BASIC_HAND_EYE

Same as PHO_MAIN_BASIC for a robot-mounted (hand-eye) scanner. The robot scans from a scanning pose. The Studio reads this pose from the Robot State Server, so R[33] / R[34] must be set correctly.

PHO_MAIN_BASIC_MULTI_VS

Two vision systems (R[30] = 1 and 2) with their own start poses (PR[2] and PR[4]). Switches the vision system after each pick.

PHO_MAIN_CHANGE_SOL

Solution requests: get the running solution, stop it, start solution R[31], and switch solutions with PHO_CHANGE_SOL after each pick.

PHO_MAIN_CHANGE_ENV

Change scene state: activates scene state R[19] with PHO_CHANGE_ENV and switches between two scene states after each pick.

PHO_MAIN_CHANGE_BBOX

Change bounding box: switches R[37] between bounding box 1 and 2 with PHO_CHANGE_BBOX after each pick.

PHO_MAIN_GET_OBJECT_POSE

Requests the object pose (PR[20]) instead of a trajectory and moves to it with a linear motion.

PHO_MAIN_GET_STATUS

Calls PHO_REQ_GET_STATUS several times after the scan to monitor the number of localized and planned objects (R[7], R[8], R[9]).

PHO_MAIN_MULTIVIEW_STATIC

Multiview: the robot stops at several poses and captures a scan at each one (PHO_REQ_CAPTURE + PHO_WAIT_SCAN, F[8] OFF). PHO_REQ_SCAN then starts the localization on the merged point cloud.

PHO_MAIN_MULTIVIEW_DYNAMIC

Multiview with dynamic meshing (MotionCam-3D only): with F[8] ON, scans are captured continuously every R[35] ms while the robot moves; F[8] OFF stops capturing.

PHO_MAIN_REUSE_SCAN

Two vision systems: VS1 is scanned, VS2 localizes on the same scan with PHO_REQ_REUSE_SCAN.

PHO_MAIN_COM_CHECK

Same as PHO_MAIN_BASIC with PHO_REQ_COM_CHECK before the main steps to detect a lost connection.

PHO_CALIBRATION

Automatic calibration from the robot: start, 9 calibration points, save, stop.

PHO_CALIBRATION_STATIC

Calibration template for a cell-mounted scanner, see Calibration example.

PHO_CALIBRATION_HAND_EYE

Same as PHO_CALIBRATION_STATIC for a robot-mounted scanner. Always restarts the Robot State Server.

3.2.1 Basic bin picking example

PHO_MAIN_BASIC starts the Robot State Server, connects to the vision controller and initializes vision system 1 with start pose PR[2] and end pose PR[3]. Then it runs a loop: scan, request and receive a trajectory, pick the object. While the robot places the object, the next scan is already running.

 1:  !Clear Registers ;
 2:  CALL PHO_CLEAR_VARS    ;
 3:   ;
 4:  !Start State Server ;
 5:  CALL PHO_RUN_STATE    ;
 6:   ;
 7:  LBL[1] ;
 8:  !Start Phoclient ;
 9:  RUN PHOCLIENT ;
10:  WAIT (F[1]=ON)    ;
11:   ;
12:  !Set Vision system ID ;
13:  R[30]=1    ;
14:  !Assign ID values of P registers ;
15:  !containing start & end poses ;
16:  R[4]=2    ;
17:  R[5]=3    ;
18:  !Initialize Binpicking ;
19:  CALL PHO_INIT    ;
20:  !Check error ;
21:  IF (R[18]<>0) THEN ;
22:  MESSAGE[PHO: Init VS failed] ;
23:  ABORT ;
24:  ENDIF ;
25:   ;
26:  LBL[2] ;
27:  !Move to Scanning Position ;
28:J P[1] 20% FINE    ;
29:  !Request First Scan ;
30:  CALL PHO_REQ_SCAN    ;
31:   ;
32:  !Main Loop ;
33:  LBL[3] ;
34:  !Wait For Scan ;
35:  CALL PHO_WAIT_SCAN    ;
36:   ;
37:  !Request trajectory ;
38:  CALL PHO_TRAJ_REQ    ;
39:  !Move to Start Position ;
40:J PR[2] 100% FINE    ;
41:   ;
42:  !Receive Trajectory ;
43:  CALL PHO_TRAJ_RECV    ;
44:   ;
45:  !Error handling ;
46:  SELECT R[18]=0,JMP LBL[4] ;
47:  !VS not initialized ;
48:         =203,JMP LBL[10] ;
49:  !Empty scene error ;
50:         =218,JMP LBL[2] ;
51:  !Path planning failed ;
52:         =201,JMP LBL[2] ;
53:  !No part found ;
54:         =202,JMP LBL[2] ;
55:  !Abort program due to fatal error ;
56:  !or logical error in program ;
57:         ELSE,JMP LBL[10] ;
58:   ;
59:  LBL[4] ;
60:  !Pick Part ;
61:  CALL PHO_PICK_PART    ;
62:  !Your placing procedure ;
63:  //J P[...] 100% FINE    ;
64:   ;
65:  !Move to Scanning Position ;
66:J P[2] 20% FINE    ;
67:  !Request Next Scan ;
68:  CALL PHO_REQ_SCAN    ;
69:  JMP LBL[3] ;
70:   ;
71:  !Abort program execution ;
72:  LBL[10] ;
73:  MESSAGE[Aborting Program] ;
74:  MESSAGE[Check BPS For Error] ;
75:  ABORT ;

3.2.2 Multiple vision systems example

PHO_MAIN_BASIC_MULTI_VS initializes two vision systems: VS1 with R[4]=2, R[5]=3 and VS2 with R[4]=4, R[5]=5. Before PHO_TRAJ_RECV, the robot moves to the start pose of the active vision system (PR[2] or PR[4]). After each pick, the program switches R[30] to the other vision system and requests a new scan.

PHO_MAIN_REUSE_SCAN has the same structure, but the second vision system uses PHO_REQ_REUSE_SCAN instead of a new scan.

3.2.3 Change solution example

PHO_MAIN_CHANGE_SOL shows how to control the deployed solution from the robot:

  1. PHO_REQ_RUN_SOL - reads the running solution into R[31].

  2. PHO_REQ_STOP_SOL - stops it.

  3. R[31]=101 and PHO_REQ_START_SOL - starts solution 101.

  4. Bin picking as in PHO_MAIN_BASIC.

  5. After each pick, the program switches R[31] between 101 and 102, and PHO_CHANGE_SOL changes the solution. Then the program jumps back to PHO_INIT, because the vision system must be initialized again after a solution change.

Use your own solution IDs from the Studio.

3.2.4 Calibration example

Calibration needs the Robot State Server with the correct R[33] / R[34] values (see Changing the Cartesian origin of the robot). The Studio reads the robot pose from the server when a calibration point is added. For the Studio side, see Calibration.

PHO_CALIBRATION_STATIC and PHO_CALIBRATION_HAND_EYE work as follows:

  1. The program calls PHO_CLEAR_VARS, starts the Robot State Server (PHO_RUN_STATE) and runs RUN PHOCLIENT.

  2. Automatic calibration only (lines 16 - 28, remarked by default): PHO_CALIB_STOP stops a running calibration, R[31] = solution ID, R[30] = vision system ID, PHO_CALIB_START starts the calibration.

  3. The robot moves to the calibration start pose and then to 9 calibration poses. At each pose PHO_CALIB_ADD adds a calibration point.

  4. The robot moves to the calibration end pose.

  5. Automatic calibration only (remarked by default): PHO_CALIB_SAVE saves the result (accuracy in R[32], result pose in PR[19]), PHO_CALIB_STOP ends the calibration.

First calibration: Start the calibration in the Studio. Run the template and leave the remarked lines remarked. Check the result and save it in the Studio.

Automatic recalibration: After the first calibration is saved and automatic calibration is enabled for the vision system in the Studio, un-remark the start and save / stop lines. The calibration object must stay where it was during the first calibration. The calibration ball stays mounted in the same place on the flange or gripper and moves with the robot. The marker pattern stays in the same place in the cell. PHO_CALIBRATION is the same template with these lines already active (solution ID 1, vision system 1).

Teach the calibration poses so that the calibration object is clearly visible and the poses differ in position and orientation. As a general rule, a calibration error above 3 mm shows a systematic problem (wrong UFRAME / UTOOL, wrong robot model or base offset).

3.3 Error handling

After every synchronous request and every program that receives a response, check R[18: PHO ERROR DATA]. The examples show a basic SELECT R[18] block after PHO_TRAJ_RECV.

What PHOCLIENT does after an error:

Error code

PHOCLIENT

Main program

201, 202, 218, 221, 453, 454, 458, 461 - 463, and codes not listed in this table (for example 200, 471, calibration point errors)

Keeps the connection and waits for the next request.

Handle the error (for example scan again) and continue.

1, 3, 4, 6, 7, 8, 203, 219, 220, 222, 255, 450 - 452, 455, 457, 459, 460, 464 - 469

Closes the connection, sets R[6] to 501 and F[1] to OFF, and ends.

Fix the cause, then RUN PHOCLIENT again and wait for F[1]. Initialize the vision systems again.

Communication error (3) is reported when the socket fails, the response does not match the request, a checksum is wrong or no data arrives for 30 s. PHOCLIENT also sets F[4] when it ends. This way, a waiting TP program continues and can read R[18]. Do not call request programs while F[1] is OFF. Otherwise, they wait until PHOCLIENT accepts the request.

Note: The basic examples stop with ABORT for all errors except 201, 202 and 218. To recover from a lost connection without aborting, jump back to RUN PHOCLIENT (label LBL[1] in the examples).

3.4 Robot State Server

Calibration, hand-eye scanning, multiview and the robot visualization in the Studio need the current robot state. The KAREL program PHOSTATE sends it:

  • TCP/IP server on Host Comm tag S3, port 11004 (written to $HOSTS_CFG[3].$SERVER_PORT by PHOSTATE).

  • After the vision controller connects, the server sends the brand ID. Then it sends, 10 times per second, the joint positions (rad) and the robot pose (mm, rad) in the frames selected by R[33] / R[34]. Changes of R[33] / R[34] take effect immediately.

  • If the robot has a linear track (RTU) mapped to X or Y, the track position is subtracted from the reported pose.

  • F[3] is ON while PHOSTATE runs.

Starting: Use CALL PHO_RUN_STATE at the beginning of the main program, or run PHO_RUN_STATE alone (select it and press SHIFT + FWD). PHO_RUN_STATE first stops a running PHOSTATE so that the new R[33] / R[34] values are used.

 1:  !KILL State server ;
 2:  F[9]=(ON) ;
 3:  WAIT   1.00(sec) ;
 4:  !Turn PHOSTATE KILL flag OFF ;
 5:  F[9]=(OFF) ;
 6:  !Turn MNUFRAME ON/OFF ;
 7:  F[10]=(OFF) ;
 8:  !Set MNUFRAME for State Server ;
 9:  R[33]=1    ;
10:  !Set MNUTOOL for State Server ;
11:  R[34]=1    ;
12:  !Start PHOSTATE ;
13:  IF (F[3]=OFF) THEN ;
14:  RUN PHOSTATE ;
15:  ENDIF ;

The USER screen shows the controller version, the module version, the IP addresses and the connection state:

PHOSTATE messages on the USER screen

Stopping: Abort All does not stop PHOSTATE. To stop it, set F[9: PHO STATE KILL] to ON. PHOSTATE stops in its next cycle. If no client is connected, it stops when the next client connects. PHO_RUN_STATE resets F[9].

Stopping PHOSTATE with flag F[9]

When the vision controller disconnects, PHOSTATE waits for a new connection. If the vision controller cannot be pinged anymore, PHOSTATE stops. In this case, check the cabling and run PHO_RUN_STATE again.

Note: Do not set PHO_RUN_STATE as a HOT START or COLD START autoexec program. PHOSTATE might not start correctly, especially on V9.

3.5 Version and brand ID

  • Robot module version: BPS 1.12.1 (shown as BPS 1.12.1/B1 on the USER screen and in the comment of the KAREL and TP programs).

  • Brand ID: ___FANUC/__F.__1._12.__0

The brand ID still contains 1.12.0 because this is the version of the communication interface, not of the Robot module. The FANUC Robot module 1.12.1 works with every BPS 1.12.x. Both PHOCLIENT and PHOSTATE send the brand ID directly after the connection is established.

4 Running the basic bin picking example program

4.1 Prerequisites

Before you run the Basic bin picking example, make sure that:

  • A BPS solution with one vision system is prepared and calibrated.

  • The robot controller is configured as described in Robot controller setup and ping works in both directions.

  • The scanning poses P[1] / P[2] and the start and end poses PR[2] / PR[3] are taught (see Reteach the robot poses).

  • The gripper programs are implemented (optional - without them, the robot does not actually pick the object).

  • The placing procedure is implemented (line 63 of the example).

4.2 Bin picking routine execution settings

PHO_PICK_PART calls PHO_EXE_TRAJ for every trajectory segment of the bin picking routine. Lines 1 - 21 set the speed R[2] (in %) of each segment by its number R[1]. By default, four segments are configured (start -> approach -> grasp -> deapproach -> end). If your grasping method has more segments, add more IF blocks. Keep the order of the segments in mind.

Warning: Do not edit lines 23 - 33!

 1:  !Binpicking speed config ;
 2:   ;
 3:  !1.Segment ;
 4:  IF (R[1]=1) THEN ;
 5:  R[2]=100    ;
 6:  ENDIF ;
 7:   ;
 8:  !2.Segment ;
 9:  IF (R[1]=2) THEN ;
10:  R[2]=50    ;
11:  ENDIF ;
12:   ;
13:  !3.Segment ;
14:  IF (R[1]=3) THEN ;
15:  R[2]=50    ;
16:  ENDIF ;
17:   ;
18:  !4.Segment ;
19:  IF (R[1]=4) THEN ;
20:  R[2]=100    ;
21:  ENDIF ;
22:   ;
23:  !Execute trajectory ;
24:  FOR R[3]=21 TO R[13] ;
25:J PR[R[3]] R[2]% CNT100    ;
26:  ENDFOR ;
27:   ;
28:  !Last Point FINE/CNT ;
29:  IF (R[16]=0) THEN ;
30:J PR[R[14]] R[2]% CNT100    ;
31:  ELSE ;
32:J PR[R[14]] R[2]% FINE    ;
33:  ENDIF ;

4.3 Reteach the robot poses

Teach the scanning pose outside the field of view of the scanner (for a hand-eye scanner: the pose from which the bin is scanned). Teach the start pose with the gripper approximately above the center of the bin. The end pose can be similar to the start pose or slightly shifted towards the placing area. Do not put the end pose too far from the bin. This makes path planning slower and can cause planning errors.

Open Data, press F1[TYPE] -> Position Reg:

DATA TYPE menu with Position Reg

Jog the robot to the pose, select the register and press SHIFT + F3[RECORD]:

Recording PR[2] and PR[3]

Start and end poses must be in Joint representation. Press F4[POSITION] -> F5[REPRE] -> Joint and confirm with CONTINUE. Do this for all start and end poses:

Position register REPRE menu with Joint

PHO_INIT sends the PRs to the Studio. Before the call, set R[4] / R[5] to the PR numbers.

4.4 Runtime

Deploy your BPS solution. On the Deployment page, the Action Request Client status is DISCONNECTED until the robot connects.

Press Select, choose PHO_MAIN_BASIC and start it in T1 (hold the deadman switch and press SHIFT + FWD):

PHO_MAIN_BASIC on the Teach Pendant

The USER screen shows the messages of PHOSTATE and PHOCLIENT. When the connection is established, Action Request Client and Robot State Server on the Deployment page change to CONNECTED and the first scan starts. When the first trajectory is received, the robot starts moving (PR[21] and higher contain the waypoints of the segment being executed).

Warning: Be ready to stop the robot at any time. Reduce the speed to 10 % for the first tests.

If the robot is too far from the object or pushes it too deep, adjust the gripping points or the tool in the Studio. To stop the program, use Function -> Abort All. This also aborts PHOCLIENT.

5 Migration guide

Read the general migration guide Migration from BPS 1.11.x to BPS 1.12.x first. Changes specific to the FANUC Robot module:

  • 1.11 -> 1.12.0: Info data are read by their key (oper_num). R[26] - R[28] now hold NN label, max Z height and tilt (see Info data). The NN label is stored without conversion.

  • 1.12.0 -> 1.12.1: F[10] is deprecated - R[33] / R[34] always apply and accept 0 (World / bare faceplate). Invalid frame numbers no longer stop the KAREL programs. The scaling of the extended axis (rail) in received trajectories is fixed. PHOCLIENT and PHOSTATE no longer change $GROUP[1].$UFRAME / $UTOOL. The brand ID is unchanged.

  • Update procedure: Robot module update.

5.1 Robot module update

  1. Back up all programs you have changed (for example PHO_GRIP_ATT or PHO_EXE_TRAJ) and your main programs.

  2. Set F[9] to ON to stop PHOSTATE, then abort all programs.

  3. Delete the old TP programs of the Robot module and PHOCLIENT.PC / PHOSTATE.PC (and their variables).

  4. Load the new files as described in Loading the Robot module files.

  5. Copy your changes into the new programs.

  6. Check the register list and the migration notes above and update your main program if needed.